<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件处理</title>
</head>
<body>
    <script>
        //unhandledrejetion事件用于捕获到未处理的Promise错误
        window.addEventListener("unhandledrejection",function(event){
            console.log(event.promise);//产生错误的promise对象
            console.log(event.reason);//Promise的reason
        });

        new Promise((resolve,reject) => {
            resolve("success");
        }).then(msg => {
            throw new Error("fail");
        });
    </script>
</body>
</html>